import Vue from 'vue'
import Router from 'vue-router'

const Login = () => import('@/views/login/Login')
const AppMain = () => import('@/views/layout/AppMain')
const Home = () => import('@/views/home/Home')
// 合约模板上传
const uploadContract = () => import('@/views/uploadContract')

export const LOGIN = 'LOGIN'
export const HOME = 'HOME'
export const UPLOAD_CONTRACT = 'UPLOAD_CONTRACT'
Vue.use(Router)
const originalPush = Router.prototype.push
const originalReplace = Router.prototype.replace
Router.prototype.push = function push (location, onResolve, onReject) {
  if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
  return originalPush.call(this, location).catch(err => err)
}
Router.prototype.replace = function replace (location, onResolve, onReject) {
  if (onResolve || onReject) return originalReplace.call(this, location, onResolve, onReject)
  return originalReplace.call(this, location).catch(err => err)
}
export default new Router({
  mode: 'history',
  base: '/agent',
  routes: [
    {
      path: '/mainLayout',
      component: AppMain,
      children: [
        {
          name: HOME,
          path: '',
          component: Home
        }
      ]
    },
    {
      name: LOGIN,
      path: '/login',
      component: Login
    },
    {
      name: UPLOAD_CONTRACT,
      path: '/uploadContract',
      component: uploadContract
    },
    {
      path: '*',
      redirect: '/Login'
    }
  ]
})
